<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>查看文件的DataUrl</title>
    <noscript>当前浏览器不支持JavaScript！</noscript>
</head>

<body>
    <input type="file" id="fileInput">
    <textarea id="result" style="
    width: 400px;
    height: 300px;
">base64</textarea>
    <script>
        var fileInput = document.querySelector('#fileInput');
        fileInput.onchange = function () {
            var file = this.files[0];
            var reader = new FileReader();
            reader.readAsDataURL(file);
            reader.onload = function () {
                document.getElementById("result").textContent = reader.result;
            };
        };
    </script>


</body>

</html>